﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Testing_components;

namespace BuildingTomorow
{
    public class PresentableGroup : INotifyPropertyChanged
    {
        private GroupDB _groupRef;
        private bool _selected;
        public ObservableCollection<PresentableSensor> Sensors
        {
            get;
            set;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public PresentableGroup()
        {
            _groupRef = new GroupDB();
        }
        public PresentableGroup(GroupDB group)
        {
            _groupRef = group;
            Sensors = new ObservableCollection<PresentableSensor>(DataAccess.GetInstance().GetSensorsForGroup(_groupRef.GroupID));
        }

        public int ID
        {
            get { return _groupRef.GroupID; }
            set
            {
                if (_groupRef.GroupID != value) _groupRef.GroupID = value;
                OnPropertyChanged("ID");
                DataAccess.GetInstance().UpdateSensors();
            }
        }

        public string Name
        {
            get { return _groupRef.Name; }
            set
            {
                if (_groupRef.Name != value) _groupRef.Name = value;
                OnPropertyChanged("Name");
                DataAccess.GetInstance().UpdateSensors();
            }
        }

        public string IconSource
        {
            get { return _groupRef.Icon; }
            set
            {
                if (_groupRef.Icon != value) _groupRef.Icon = value;
                OnPropertyChanged("IconSource");
                DataAccess.GetInstance().UpdateSensors();
            }
        }

        public bool IsGroupSelected
        {
            get { return _selected; }
            set
            {
                if (_selected != value) _selected = value;
                OnPropertyChanged("IsGroupSelected");
                // no reason maybe
               // DataAccess.GetInstance().UpdateSensors();
            }
        }
    }
}
